<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ include file="admin_Header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Delete Product</title>
</head>
<body>
<center>
	<h1>Product Compare Application</h1>
	<button id="List" onclick="window.location.href='admin_ListProducts.jsp'">Get Product List</button>
	<button id="AddProduct" onclick="window.location.href='admin_AddProduct.jsp'">Add New Product</button>
	<button id="AddSuperMarket" onclick="window.location.href='admin_AddSupermarket.jsp'">Add New SuperMarket</button>
	<button id="ManageSuperMarket" onclick="window.location.href='admin_ManageSupermarket.jsp'">Manage Supermarket</button>
	<button id="DeleteProduct" onclick="window.location.href='admin_DeleteProduct.jsp'">Delete Product</button>
	<button id="DeleteSupermarket" onclick="window.location.href='admin_DeleteSupermarket.jsp'">Delete Supermarket</button>
</center>
<center>
<br><br>
<%
	if (request.getParameter("productId") != null)
	{
	    try
	    {
	    	Product product = iproducts.FindProductById(Integer.valueOf(request.getParameter("productId")));
	    	iproducts.DeleteProduct(product);
	    }
	    catch (Exception e)
	    {
	        throw new Exception("Error in connecting to database, please contact your administrator");
		}
	}
	else
	{
		out.println("<form action=\"admin_DeleteProduct.jsp\">");
		try
		{
			List<Product> products = iproducts.FindAllProducts();
			out.println("<select name=\"productId\">");
			for (Product product : products)
			{
				System.out.println("<option name=\"productId\" value=\"" + product.getProductId() +"\"> " + product.getProductName() +"</option>");
				out.println("<option name=\"productId\" value=\"" + product.getProductId() +"\"> " + product.getProductName() +"</option>");
			}
			out.println("</select>");
			out.println("<button type=\"submit\">Delete</button>");
			out.println("</form>");
		}
		catch (Exception e)
		{
		    throw new Exception("Error in connecting to database, please contact your administrator");
		}
	}
%>
</center>
</body>
</html>